﻿using System;
using System.Collections.Generic;

namespace 手动蛇形填bug
{
    class MainClass
    {
        static int now = 1;
        static int xC = 0;
        static int yC = 0;
        public static void Main(string[] args)
        {
            var intList = new List<int>();
            var unsuccedd = true;
            while (unsuccedd)
            {
                intList = new List<int>();
                var input = Console.ReadLine().Split(' ');
                try
                {
                    foreach (var values in input)
                        intList.Add(Convert.ToInt32(values));
                    unsuccedd = false;
                }
                catch(FormatException)
                {
                    unsuccedd = true;
                }
            }
            int x = intList[0], y = intList[1];
            var youMotherFucker = new int[x, y];
            ShowThisMotherFucker(x, y, youMotherFucker);
            while (true)
            {
                var inputKey = Console.ReadKey(true).Key;
                if (inputKey.Equals(ConsoleKey.UpArrow) && xC > 0)
                    xC--;
                else if (inputKey.Equals(ConsoleKey.DownArrow) && xC < x - 1)
                    xC++;
                else if (inputKey.Equals(ConsoleKey.RightArrow) && yC < y - 1)
                    yC++;
                else if (inputKey.Equals(ConsoleKey.LeftArrow) && yC > 0)
                    yC--;
                else if (inputKey.Equals(ConsoleKey.Spacebar))
                {
                    youMotherFucker[xC, yC] = now++;
                }
                else if (inputKey.Equals(ConsoleKey.Escape))
                {
                    youMotherFucker = new int[x, y];
                    now = 1;
                    xC = 0;
                    yC = 0;
                }
                Console.Clear();
                ShowThisMotherFucker(x, y, youMotherFucker);
            }
        }
        static public void ShowThisMotherFucker(int x, int y, int[,] motherFucker)
        {
            for (int i = 0; i < x; i++){
                for (int j = 0; j < y; j++)
                {
                    if ((i == xC) && (j == yC))
                        Console.Write(">");
                    if (motherFucker[i, j] < 10)
                        Console.Write(' ');
                    Console.Write($"{motherFucker[i, j]} ");
                }
                Console.WriteLine();
            }
            Console.WriteLine($"current : x-{xC} y-{yC} now-{now}");
        }
    }

}
